<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="4" :sm="6">
            <a-form-item label="名称">
              <a-input placeholder="请输入名称" v-model="queryParam.advanceName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="6">
            <a-form-item label="类型">
              <a-select allowClear placeholder="请选择类型" v-model="queryParam.advanceType">
                <a-select-option :value="item.value" v-for="item in typeList" :key="item.id">{{
                  item.label
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="6">
            <a-form-item label="年份">
              <a-date-picker
                mode="year"
                placeholder="请选择年份"
                format="YYYY"
                :allowClear="false"
                value-format="yyyy-MM-dd"
                v-model="queryParam.advanceYear"
                :open="yearPickShow"
                style="width: 100%"
                @panelChange="handlePanelChange"
                @openChange="handleOpenChange"
              />
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="6">
            <a-form-item label="申报单位">
            <j-select-depart
                v-model="queryParam.submitDeptId"
                :trigger-change="true"
                customReturnField="id"
                :multi="true"
              ></j-select-depart>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="6">
            <a-form-item label="申报人员">
              <a-input placeholder="请输入申报人员" v-model="queryParam.submitPeoName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-tabs default-active-key="0" @change="handleTabChange">
      <a-tab-pane key="0" tab="未审批">
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns1"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          @change="handleTableChange"
        >
          <span slot="附件" slot-scope="text, record">
            <a-button size="small" type="link" @click="handleLookFile(record, '查看附件')">查看</a-button>
          </span>
          <span slot="actionName">
            <a-button size="small" @click="openCreatModel()" type="primary" icon="plus">新增</a-button>
          </span>
          <span slot="action" slot-scope="text, record">
            <a @click="handleDetail(record, tiileCase[record.advanceType])">查看</a>
            <a-divider type="vertical" />
            <a-dropdown>
              <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
              <a-menu slot="overlay">
                <a-menu-item>
                  <a @click="openCreatModel(record)">处理</a>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </span>
        </a-table>
      </a-tab-pane>
      <a-tab-pane key="1" tab="已审批">
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns2"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          @change="handleTableChange"
        >
          <span slot="附件" slot-scope="text, record">
            <a-button size="small" @click="handleLookFile(record, '查看附件')" type="link">查看</a-button>
          </span>
          <span slot="actionName">
            <a-button size="small" @click="openCreatModel()" type="primary" icon="plus">新增</a-button>
          </span>
          <span slot="action" slot-scope="text, record">
            <a @click="handleDetail(record, tiileCase[record.advanceType])">查看</a>
          </span>
        </a-table>
      </a-tab-pane>
    </a-tabs>
    <!-- table区域-end -->

    <create ref="creatModel" @submited="loadData"></create>
    <CheckAndEditModel ref="modalForm"></CheckAndEditModel>
    <FileModel ref="fileModel" :disDel="true"></FileModel>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { columns1, columns2 } from './indexColumns'
import create from './create'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'
import moment from 'moment'
import CheckAndEditModel from './CheckAndEditModel.vue'
import FileModel from '../components/FileModel.vue'

export default {
  name: 'jh',
  mixins: [JeecgListMixin],
  components: {
    create,
    CheckAndEditModel,
    FileModel,
  },
  data() {
    return {
      // 表头
      columns1: columns1(this),
      columns2: columns2(this),
      url: {
        list1: '/check/assessment/queryAdByPage',
        list: '',
        ys: '/check/assessment/selectAppDone',
      },
      yearPickShow: false,
      tiileCase: {
        单位: '审计先进单位申报表',
        个人: '审计先进工作者申报表',
      },
      typeList: [
        {
          id: '1',
          label: '个人申报',
          value: '个人',
        },
        {
          id: '2',
          label: '单位申报',
          value: '单位',
        },
      ],
      dataSource: [
        {
          序号: 1,
          名称: 'xxxxxxxxx',
          年份: '2021',
          类型: '年份',
          审批状态: '待审批',
          申报单位: 'xxxxxxx',
          申报人员: '张丽',
        },
      ],
    }
  },
  computed: {},
  created() {
    this.url.list = this.url.list1
  },
  mounted() {},
  methods: {
    // TODO 上传附件
    handleLookFile(record, name) {
      // this.getFileList(record)
      // this.$refs.fileModel.visible = true
      this.$refs.fileModel.title = name
      this.$refs.fileModel.look(record,'sp')
    },
    openCreatModel(record) {
      if (record) {
        this.$refs.creatModel.rowData = record
      }
      this.$refs.creatModel.visible = true
    },
    handlePanelChange(value) {
      this.queryParam.advanceYear = moment(value).format('YYYY')
      this.yearPickShow = false
    },
    // 弹出日历和关闭日历的回调
    handleOpenChange(status) {
      this.yearPickShow = status
      if(this.queryParam.advanceYear){
        this.queryParam.advanceYear = moment(this.queryParam.advanceYear.slice(0, 4)).format('YYYY')
      }
    },
    handleTabChange(e) {
      this.url.list = e == '0' ? this.url.list1 : this.url.ys
      this.dataSource = []
      this.loadData()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>